<?php
namespace Modules\Frontend\Controllers;

class UserWalletController extends \Phalcon\Mvc\Controller {
	public function beforeExecuteRoute() {
		\Components\Utils::isClosedFrontent($this);
	}

	public function initialize() {
		$this -> response -> setStatusCode(200, 'OK') -> sendHeaders() -> setContentType('application/json', 'UTF-8');
	}

	public function indexAction() {
		$serviceF = $this -> account::getServiceInstance() -> checkLogin($this -> request -> getQuery('token', 'string', null));
		if($serviceF['code'] != 0) {
			return $this -> response -> setJsonContent(['code'=>$serviceF['code'],'msg'=>$serviceF['message']]);
		}

		$serviceS = $this -> account::getWalletServiceInstance() -> findFirstById($serviceF['user'] -> user_id);
		if($serviceS['code'] != 0) {
			return $this -> response -> setJsonContent(['code'=>$serviceS['code'],'msg'=>$serviceS['message']]);
		}

		return $this -> response -> setJsonContent(['code'=>0,'msg'=>'Success','user' => $serviceF['user'],'user_wallet'=>$serviceS['user_wallet']]);
	}
}